package com.yedou.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Result(){

    }

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    // 添加分页数据静态方法
    public static <T> Result<PageResult<T>> pageSuccess(PageResult<T> pageResult) {
        Result<PageResult<T>> result = new Result<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(pageResult);
        return result;
    }

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }

    public static<T> Result ok(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData(data);
        return result;
    }


    public static Result ok(Integer resultCode, String resultMessage){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    public static<T> Result ok(Integer resultCode, String resultMessage, T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static<T> Result fail(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }

    public static Result fail(Integer resultCode, String resultMessage){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;
    }

    public static<T> Result fail(Integer resultCode, String resultMessage, T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

}
